<?=$this->render('header.phtml');?>

<? extract($this->getVars(), EXTR_REFS); ?>

<style type="text/css">
a img {border:none;}
#tree {float:left;}
#list {margin-left:300px;}
</style>

<div id="main">
    <div id="tree">
        <div style="margin:5px;">
        <input type="button" value="New Folder" class="button" onclick="location='/file/folder'" />
        <input type="button" value="Upload File" class="button" onclick="location='/file/upload?folder_id=<?=$folderId?>'" />
        </div>
        <div style="margin:5px;"><a href="javascript:d.openAll();"><b>Expand All</b></a>&nbsp; | &nbsp;<a href="javascript:d.closeAll();"><b>Collapse All</b></a></div>
        <script type="text/javascript">
        d = new dTree('d');
        d.add(0, -1, '<b><a href="/file/list">Root Folder</a></b>');
        <? foreach ($folders as $item) { ?>
        <? if ($folderId == $item['folder_id']) $name = "<font color=green>{$item['folder_name']}</font>"; else $name = $item['folder_name'] ?>
        d.add(<?=$item['folder_id']?>, <?=$item['parent_id']?>, '<?=$name?>', '<?=$this->url(array('folder_id' => $item['folder_id'], 'page' => null))?>', '<?=$item['folder_name']?>', '_self', '/images/dtree/folder.gif');
        <? } ?>
        document.write(d);
        </script>
    </div> <!-- end #tree -->

    <div id="list">
        <fieldset style="width:600px;">
        <legend>Search</legend>
        <form action="<?=$this->url()?>">
        <input type="text" name="keyword" value="" size="100" /> <input type="submit" value="Search" class="button" />
        </form>
        </fieldset>
        <table class="tablegrid" width="100%">
        <tr><th>File Name</th><th>File Size(Byte)</th><th>Created Time</th><th>Updated Time</th><th>Description</th><th>Action</th></tr>
        <? foreach ($paginator as $row) { ?>
        <tr>
        <td><a href="<?=$row['path']?>" title="Download file"><?=SalesHero_Util::highlight($row['filename'], $keyword)?></a></td>
        <td><?=$row['filesize']?></td>
        <td><?=$row['created']?></td>
        <td><?=$row['modified']?></td>
        <td><?=$row['description']?></td>
        <td>
        <a href="<?=$row['path']?>" title="Download file"><img src="/images/icon/disk.gif" /></a>
        <a href="/file/edit/id/<?=$row['file_id']?>" title="Edit file info"><img src="/images/icon/edit.gif" /></a>
        <a href="/file/delete/id/<?=$row['file_id']?>" class="delete" title="Delete this file"><img src="/images/icon/trash.gif" /></a>
        </td>
        </tr>
        <? } ?>
        </table>
        <?=$this->paginationControl($paginator, 'Sliding', 'paginator/search.phtml'); ?>
    </div> <!-- end #list -->
    <div class="clearfloat"></div>
</div> <!-- end #main -->

<?=$this->render('footer.phtml');?>

<script type="text/javascript">
$().ready(function() {
    <? if (!empty($folderId)) { ?>
    d.openTo(<?=$folderId?>);
    <? } ?>
});
</script>